package fc.sj.study.activity.imactivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import butterknife.ButterKnife;
import butterknife.OnClick;
import fc.sj.study.R;
import io.rong.imkit.RongIM;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.UserInfo;

/**
 * 会话界面
 */
public class ConversationActivity extends FragmentActivity  {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_conversation);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.title)
    public void onViewClicked() {
        if (RongIM.getInstance() != null)
            RongIM.getInstance().startConversationList(ConversationActivity.this);

    }

    private void init() {
        RongIM.setConversationBehaviorListener(new RongIM.ConversationBehaviorListener() {

            @Override
            public boolean onUserPortraitClick(Context context, Conversation.ConversationType conversationType, UserInfo userInfo) {
                //在这里处理你想要跳转的activity，示例代码为YourAcitivy
                Intent in = new Intent(context, UserInfoActivity.class);
                context.startActivity(in);
                return false;
            }

            @Override
            public boolean onUserPortraitLongClick(Context context, Conversation.ConversationType conversationType, UserInfo userInfo) {
                return false;
            }

            @Override
            public boolean onMessageClick(Context context, View view, Message message) {
                //点击消息处理事件，示例代码展示了如何获得消息内容
//                if (message.getContent() instanceof LocationMessage) {
//                    Intent intent = new Intent(context, LocationActivity.class);
//                    intent.putExtra("location", message.getContent());
//                    context.startActivity(intent);
//
//                } else if (message.getContent() instanceof RichContentMessage) {
//                    RichContentMessage mRichContentMessage = (RichContentMessage) message.getContent();
//                    Log.d("Begavior", "extra:" + mRichContentMessage.getExtra());
//
//                }
//
//                Log.d("Begavior", message.getObjectName() + ":" + message.getMessageId());
                return false;
            }

            @Override
            public boolean onMessageLinkClick(Context context, String s) {
                return false;
            }

            @Override
            public boolean onMessageLongClick(Context context, View view, Message message) {
                return false;
            }

        });
    }

}
